package com.neulogistics.core.customercenter.infrastructure.persistence.orm.po;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@TableName(value ="tb_order", autoResultMap = true)
@Data
public class OrderPO implements Serializable {
    /**
     * 订单id
     */
    @TableId(value = "order_id", type = IdType.INPUT)
    private Long orderId;

    /**
     * 订单类型：1：配送单；2：退货单；3：换货单
     */
    @TableField(value = "order_type")
    private Integer orderType;

    /**
     * 客户id
     */
    @TableField(value = "customer_id")
    private Integer customerId;

    /**
     * 订单项，用来储存订单中的商品信息，包含商品id、数量、单价、计量单位
     */
    @TableField(value = "order_items", typeHandler = JacksonTypeHandler.class)
    private JSONArray orderItems;

    /**
     * 订单状态：0：新建；1：缺货；2：待调度；3：待出库；4：运输中；5：到达分站；6：派送中；7：已完成；8：已退货；9：已换货
     */
    @TableField(value = "order_status")
    private Integer orderStatus;

    /**
     * 总额
     */
    @TableField(value = "total_amount")
    private Integer totalAmount;

    /**
     * 备注信息
     */
    @TableField(value = "order_remark")
    private String orderRemark;

    /**
     * 收货地址{省，市，区，详细}
     */
    @TableField(value = "receiver_address", typeHandler = JacksonTypeHandler.class)
    private JSONObject receiverAddress;

    /**
     * 收货人名
     */
    @TableField(value = "receiver_name")
    private String receiverName;

    /**
     * 收货人电话
     */
    @TableField(value = "receiver_phone")
    private String receiverPhone;

    /**
     * 是否需要发票：0:不需要；1:需要
     */
    @TableField(value = "opt_invoice")
    private Integer optInvoice;

    /**
     * 发票id
     */
    @TableField(value = "invoice_id")
    private Long invoiceId;

    /**
     * 期望配送时间
     */
    @TableField(value = "exp_delivery_time")
    private Date expDeliveryTime;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 创建人id
     */
    @TableField(value = "creator_id")
    private Integer creatorId;

    /**
     * 发货时间
     */
    @TableField(value = "shipped_time")
    private Date shippedTime;

    /**
     * 成交时间
     */
    @TableField(value = "complete_time")
    private Date completeTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    private Date updateTime;

    /**
     * 是否删除
     */
    @TableField(value = "deleted")
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        OrderPO other = (OrderPO) that;
        return (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
                && (this.getOrderType() == null ? other.getOrderType() == null : this.getOrderType().equals(other.getOrderType()))
                && (this.getCustomerId() == null ? other.getCustomerId() == null : this.getCustomerId().equals(other.getCustomerId()))
                && (this.getOrderItems() == null ? other.getOrderItems() == null : this.getOrderItems().equals(other.getOrderItems()))
                && (this.getOrderStatus() == null ? other.getOrderStatus() == null : this.getOrderStatus().equals(other.getOrderStatus()))
                && (this.getTotalAmount() == null ? other.getTotalAmount() == null : this.getTotalAmount().equals(other.getTotalAmount()))
                && (this.getOrderRemark() == null ? other.getOrderRemark() == null : this.getOrderRemark().equals(other.getOrderRemark()))
                && (this.getReceiverAddress() == null ? other.getReceiverAddress() == null : this.getReceiverAddress().equals(other.getReceiverAddress()))
                && (this.getReceiverName() == null ? other.getReceiverName() == null : this.getReceiverName().equals(other.getReceiverName()))
                && (this.getReceiverPhone() == null ? other.getReceiverPhone() == null : this.getReceiverPhone().equals(other.getReceiverPhone()))
                && (this.getOptInvoice() == null ? other.getOptInvoice() == null : this.getOptInvoice().equals(other.getOptInvoice()))
                && (this.getInvoiceId() == null ? other.getInvoiceId() == null : this.getInvoiceId().equals(other.getInvoiceId()))
                && (this.getExpDeliveryTime() == null ? other.getExpDeliveryTime() == null : this.getExpDeliveryTime().equals(other.getExpDeliveryTime()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId()))
                && (this.getShippedTime() == null ? other.getShippedTime() == null : this.getShippedTime().equals(other.getShippedTime()))
                && (this.getCompleteTime() == null ? other.getCompleteTime() == null : this.getCompleteTime().equals(other.getCompleteTime()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
                && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.getOrderId() == null) ? 0 : this.getOrderId().hashCode());
        result = prime * result + ((getOrderType() == null) ? 0 : getOrderType().hashCode());
        result = prime * result + ((getCustomerId() == null) ? 0 : getCustomerId().hashCode());
        result = prime * result + ((getOrderItems() == null) ? 0 : getOrderItems().hashCode());
        result = prime * result + ((getOrderStatus() == null) ? 0 : getOrderStatus().hashCode());
        result = prime * result + ((getTotalAmount() == null) ? 0 : getTotalAmount().hashCode());
        result = prime * result + ((getOrderRemark() == null) ? 0 : getOrderRemark().hashCode());
        result = prime * result + ((getReceiverAddress() == null) ? 0 : getReceiverAddress().hashCode());
        result = prime * result + ((getReceiverName() == null) ? 0 : getReceiverName().hashCode());
        result = prime * result + ((getReceiverPhone() == null) ? 0 : getReceiverPhone().hashCode());
        result = prime * result + ((getOptInvoice() == null) ? 0 : getOptInvoice().hashCode());
        result = prime * result + ((this.getInvoiceId() == null) ? 0 : this.getInvoiceId().hashCode());
        result = prime * result + ((getExpDeliveryTime() == null) ? 0 : getExpDeliveryTime().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode());
        result = prime * result + ((getShippedTime() == null) ? 0 : getShippedTime().hashCode());
        result = prime * result + ((getCompleteTime() == null) ? 0 : getCompleteTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", orderId=").append(orderId);
        sb.append(", orderType=").append(orderType);
        sb.append(", customerId=").append(customerId);
        sb.append(", orderItems=").append(orderItems);
        sb.append(", orderStatus=").append(orderStatus);
        sb.append(", totalAmount=").append(totalAmount);
        sb.append(", orderRemark=").append(orderRemark);
        sb.append(", receiverAddress=").append(receiverAddress);
        sb.append(", receiverName=").append(receiverName);
        sb.append(", receiverPhone=").append(receiverPhone);
        sb.append(", optInvoice=").append(optInvoice);
        sb.append(", invoiceId=").append(invoiceId);
        sb.append(", expDeliveryTime=").append(expDeliveryTime);
        sb.append(", createTime=").append(createTime);
        sb.append(", creatorId=").append(creatorId);
        sb.append(", shippedTime=").append(shippedTime);
        sb.append(", completeTime=").append(completeTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", deleted=").append(deleted);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
